package com.itheima.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mapper.CmsPrefrenceAreaProductRelationMapper;
import com.itheima.pojo.db.CmsPrefrenceAreaProductRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
/**
 * @author chensen
 * @create 2022/10/14/20:39
 */
@DubboService
public class CmsPrefrenceAreaProductRelationApiImpl implements CmsPrefrenceAreaProductRelationApi {
    @Autowired
    private CmsPrefrenceAreaProductRelationMapper cmsPrefrenceAreaProductRelationMapper;

    @Override
    public void insertList(List<CmsPrefrenceAreaProductRelation> list, Long productId) {
        for (CmsPrefrenceAreaProductRelation cmsPrefrenceAreaProductRelation : list) {
            cmsPrefrenceAreaProductRelation.setId(null);
            cmsPrefrenceAreaProductRelation.setPrefrenceAreaId(productId);
            cmsPrefrenceAreaProductRelationMapper.insert(cmsPrefrenceAreaProductRelation);
        }
    }

    @Override
    public void deleteById(Long id) {
        cmsPrefrenceAreaProductRelationMapper.delete(new LambdaQueryWrapper<CmsPrefrenceAreaProductRelation>().eq(CmsPrefrenceAreaProductRelation::getProductId, id));
    }

    @Override
    public List<CmsPrefrenceAreaProductRelation> selectByPid(Long id) {
        return cmsPrefrenceAreaProductRelationMapper.selectList(new LambdaQueryWrapper<CmsPrefrenceAreaProductRelation>().eq(CmsPrefrenceAreaProductRelation::getProductId, id));
    }
}
